package net.huashitong.user.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.sirdc.modules.core.web.JsonBaseController;
import com.sirdc.modules.core.web.model.Message;
import com.sirdc.modules.sys.entity.SysPicture;
import com.sirdc.modules.sys.service.SysFileService;
import com.sirdc.modules.sys.service.SysPictureService;
/**
 * 批量上传文件
 * @author lzr
 *
 */
@Controller
@RequestMapping("/pictureUpload")
public class PictureUploadController extends JsonBaseController {

	@Autowired
	private SysPictureService sysPictureService;
	@Autowired
	private SysFileService sysFileService;
	@Override
	protected String getView(String arg0) {
		// TODO Auto-generated method stub
		return null;
	}
	
	@ResponseBody
	@RequestMapping("/uploadBatch")
	public Message uploadBatch(@RequestParam MultipartFile[] files) throws Exception {
		if (files == null || files.length==0) {
			return coverMessage("500", "上传文件为空");
		}
		List<Map<String, Object>> maps = new ArrayList<Map<String,Object>>(); 
		for (MultipartFile multipartFile : files) {
			SysPicture sysPicture = new SysPicture();
			sysPictureService.savePicture(sysPicture, multipartFile);
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("sysId", sysPicture.getSysId());
			maps.add(map);
		}
		
		return coverMessage("200", "上传文件成功", maps);
	}
}
